navigatorUtils = {

	goToUrl : function(arg) {
		var url = arg.children[0].getAttribute('href');
		window.location.href = url;
	},
	htmlVal : function(data, index) {
		var compiled = _.template('<p><span class="commitDate"><%= date %></span> Rev=<%= revision %><br /> Author: <span class="italic-font"><%= author %></span> <br /> Comment: <span class="italic-font"><%= message %></span></p>');

		return compiled({
			date : $.format.date(new Date(data[index].date), 'MM/dd/yyyy'),
			revision : data[index].revision,
			author : data[index].author,
			message : data[index].message
		});
	},
	rev : 0,

	showHistory : function() {
		$.ajax({
			url : '/training/svn/commitHistory',
			dataType : 'json',
			data : {
				revision : this.rev
			},
			ifModified : true,
			success : function(data, textStatus) {
				if (textStatus != 'notmodified') {
					navigatorUtils.rev = data[0].revision;
					$('#history #lastCommits').empty();
					$.each(data, function(index) {
						var text = navigatorUtils.htmlVal(data, index);
						$('#history #lastCommits').append(text);
					});
				}
				;
			}
		});
	},

	onClickHandler : function() {
		$('p.repositoryNode').click(function() {
			navigatorUtils.goToUrl(this);
		});
	}

};

$(document).ready(function() {
	navigatorUtils.showHistory();
	setInterval("navigatorUtils.showHistory();", 15000);
	navigatorUtils.onClickHandler();
});